-- DragonShadow
-- Created by chengb Jan/28/2016
-- 神龙虚影建筑格子

-- 初始化
function initDragonShadow(self)
    self.item:removeAllChildren();

    local class = self.gridData.class;
    local buildingInfo = BuildingBonusM.queryBuildingView(class);

    if not buildingInfo then
        error("获取不到建筑查看配置，元素类型：" .. class);
        return;
    end

    local function onClicked(sender, eventType)
        if eventType == ccui.TouchEventType.began then
            if self.gridData.state == GRID_STATE_DISABLE then
                -- 已经失效，不处理
                return;
            end

            -- 如果还有怪物没有死亡
            if not DungeonM.isAllMonsterDead() then
                self:openBuildingView(nil, nil, buildingInfo["dialog2"], buildingInfo["view_text2"]);
                return;
            end

            -- 获取已获得神龙虚影奖励的次数
            local bonusTimes = SkyInstanceM.getDragonShadowBonusTimes();

            local function okFunc()
                -- 执行神龙虚影事件
                local pos = self.gridData:getPos();
                DungeonActionM.go("dragon_shadow", pos);
            end

            local dialog = buildingInfo["dialog"];

            self:openBuildingView(okFunc, nil, dialog);
        end
    end

    local iconPath = getLevelItemIconPath(buildingInfo["icon"]);
    self.icon = ccui.ImageView:create(iconPath);
    self.icon:setTouchEnabled(true);
    self.icon:addTouchEventListener(onClicked);
    self.item:addChild(self.icon);
end

